﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using KeRui.Common;
using System.Collections.Generic;

public partial class Manage_Cms_EmailValidate : System.Web.UI.Page
{
    #region 定义相关变量
    protected KeRui.BLL.Validate bllValidate = new KeRui.BLL.Validate();
    protected KeRui.Model.Validate modelValidate = new KeRui.Model.Validate();
    protected KeRui.BLL.Member bllMember = new KeRui.BLL.Member();
    protected KeRui.BLL.CmsSite bllCmsSite = new KeRui.BLL.CmsSite();
    protected int PageSize = 20;                               //每页数量
    protected int PageIndex = KeRui.Common.PageRequest.GetInt("page", 1);   //请求的页码
    protected int PageCS = KeRui.Common.PageRequest.GetInt("cs", -1);       //记录总数
    protected int PageCount = 0;                               //总页数
    protected string PageShow = "";                            //分页显示
    private int g_SiteID = 99;   //站点ID
    protected DataTable dt;
    protected List<string> emailList = new List<string>();
    #endregion

    protected void Page_Load(object sender, EventArgs e)
    {
        ManageHelper.CheckAdminLogin();//登陆判断

        if (ManageHelper.PageAct() == "validate")
        {
            SendValidateEmail();
        }
        GetInfo();
    }

    #region 获取页面数据信息
    /// <summary>
    /// 获取页面数据信息
    /// </summary>
    private void GetInfo()
    {
        dt = bllValidate.GetList(PageSize, PageIndex, " 1=1 AND Type ='邮箱验证'", " State ASC,RequestTime DESC");

        if (dt.Rows.Count > 0)
        {
            //绑定认证邮箱
            for (int i = 0; i < dt.Rows.Count; i++)
            {
                string strEmail = bllMember.GetModel(int.Parse(dt.Rows[i]["UserID"].ToString())).Email;
                emailList.Add(strEmail);
            }
        }
        else
        {
            dt = new DataTable();
        }

        //总数
        if (PageCS == -1)
            PageCS = bllValidate.GetCount(" 1=1 AND Type ='邮箱验证'");
        //总页数
        if (PageCS % PageSize == 0)
            PageCount = PageCS / PageSize;
        else
            PageCount = PageCS / PageSize + 1;
        //分页显示
        PageShow = ManageHelper.showSplitPage("EmailValidate.aspx?cs=" + PageCS.ToString() + "&page={0}", PageIndex, PageSize, PageCS);
    }
    #endregion

    #region 发送邮箱认证邮件
    /// <summary>
    /// 发送邮箱认证邮件
    /// </summary>
    private void SendValidateEmail()
    {
        string SiteName = bllCmsSite.GetModel(g_SiteID).SiteName;
        string ret = ManageHelper.MailSend4Info(PageRequest.GetString("email"), "<" + SiteName + ">邮箱认证激活", "恭喜您，您已经成功注册了" + SiteName + "网!您收到的是" + SiteName + "网邮箱的验证邮件，邮件成功验证可提高信用！<br /><br />请点击以下网址,以完成邮箱的验证:<br /><a href='http://info.iportalcms.cn/Member/info/Validatetip.aspx?id=" + PageRequest.GetInt("id", 0) + "&guid=" + PageRequest.GetString("guid") + "'>http://info.iportalcms.cn/Member/info/Validatetip.aspx?id=" + PageRequest.GetInt("id", 0) + "&guid=" + PageRequest.GetString("guid") + "</a><br /><br /><br /><br />(这是一封自动产生的Email，请勿回复!)", SiteName + "邮箱认证中心");
        if (ret == "ok")
        {
            modelValidate = new KeRui.Model.Validate();
            modelValidate.Id = PageRequest.GetInt("id", 0);
            modelValidate.State = 3;    //0：未处理 1：未通过 2：通过 3:已处理，等待激活
            modelValidate.TransactTime = DateTime.Parse("1900-1-1 0:00:00");
            bllValidate.Update(modelValidate);

            Response.Redirect("EmailValidate.aspx?sucmsg=邮件发送成功！");
        }
        else
            Response.Redirect("EmailValidate.aspx?errmsg=" + Utils.RemoveHtmlContent(ret));
    }
    #endregion
}